/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package helpdiabetesj2me;

import javax.microedition.lcdui.*;

/**
 *
 * @author Johan
 */
public class InitialScreen extends MyCanvas implements CommandListener {

        static final String[] str_ok ={"Ok"};
         static final String[]str_startmessage1 ={"De Creative Commons Naamsvermelding 2.0 België Licentie is van toepassing op dit werk. "};
         static final String[]str_startmessage2 ={"Ga naar http://creativecommons.org/licenses/by/2.0/be/deed.nl  om deze licentie te bekijken."};
         static final String[]str_startmessage3 ={"Deze licentie is niet van toepassing op de inhoud van de voedingsmiddelentabellen. Deze tabellen werden overgenomen van andere bronnen"};
         static final String[]str_startmessage4 ={" en vallen dus ook onder de licentievoorwaarden gesteld door de originele auteurs van deze tabellen."};
         static final String[]str_startmessage5 ={"Meer info omtrent de bronnen van de voedingsmiddelentabellen vindt U later via optie 'Info/Help'"};
         static final String[]str_startmessage6 ={"Voor meer info ga naar http://www.johandegraeve.net"};
 		static final String[]str_afsl ={"Afsluiten"};
         static final String[]str_afsl_short ={"Exit"};
         static final String[]str_licenseagreement ={"Licentieovereenkomst"};


    private Command exit;
    private Command ok;

    boolean start_message_completely_shown;
    boolean bottom_reached;
    int offset;

    public InitialScreen(Font userfont,HelpDiabetes midlet)  {
        super(userfont,midlet);
        enteredstring = null;

        //first sleep a period, to make sure screen is swapped to getitemfromuser
        try {
           Thread.sleep(250);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
        curdisp = midlet.getDisplay().getCurrent();
        midlet.getDisplay().setCurrent(this);

        bottom_reached =false;

        offset = 0;
        repaint();

        exit = new Command(str_afsl_short[HelpDiabetes.languageIndex],str_afsl[HelpDiabetes.languageIndex],Command.EXIT,1);
        this.addCommand(exit);
        ok = new Command(str_ok[HelpDiabetes.languageIndex],Command.OK,1);
        this.setCommandListener(this);

    }
    protected void paint(Graphics graphics) {
        //setscrsize();
        graphics.setFont(userfont);
        graphics.setColor(255,255,255);
        graphics.fillRect(0, 0, scrwidth, scrhght);
        x = 0;
        y= offset;
        paintstring(("HelpDiabetes" ).getBytes(), ("HelpDiabetes" ).length(), true, graphics, userfont);
        y = y + fonthght;x = 0;
        paintstring((str_licenseagreement[HelpDiabetes.languageIndex]).getBytes(), ( str_licenseagreement[HelpDiabetes.languageIndex]).length(), true, graphics, userfont);
        y = y + fonthght;x = 0;
        paintstring(str_startmessage1[HelpDiabetes.languageIndex].getBytes(),str_startmessage1[HelpDiabetes.languageIndex].length(),false,graphics,userfont,true);
        y = y + fonthght;x = 0;
        paintstring(str_startmessage2[HelpDiabetes.languageIndex].getBytes(),str_startmessage2[HelpDiabetes.languageIndex].length(),false,graphics,userfont,true);
        y = y + fonthght;x = 0;
        y = y + fonthght;x = 0;
        paintstring(str_startmessage3[HelpDiabetes.languageIndex].getBytes(),str_startmessage3[HelpDiabetes.languageIndex].length(),false,graphics,userfont,true);
        paintstring(str_startmessage4[HelpDiabetes.languageIndex].getBytes(),str_startmessage4[HelpDiabetes.languageIndex].length(),false,graphics,userfont,true);
        y = y + fonthght;x = 0;
        paintstring(str_startmessage5[HelpDiabetes.languageIndex].getBytes(),str_startmessage5[HelpDiabetes.languageIndex].length(),false,graphics,userfont,true);
        y = y + fonthght;x = 0;
        y = y + fonthght;x = 0;
        if (!paintstring(str_startmessage6[HelpDiabetes.languageIndex].getBytes(),str_startmessage6[HelpDiabetes.languageIndex].length(),false,graphics,userfont,true)) {
            //the text was not completely shown on the screen
            //start by erasing the last line
            graphics.setColor(255,255,255);
            graphics.fillRect(0,scrhght-fonthght,scrwidth,scrhght);
            //now draw a small triangle pointing downward to show there's more text
            graphics.setColor(0,0,0);
            graphics.fillTriangle(scrwidth/2-5, scrhght-fonthght, scrwidth/2+5, scrhght-fonthght, scrwidth/2,scrhght);

        } else {//text completely shown, 'ok' button can be added.
            this.addCommand(ok);
            start_message_completely_shown = true;
            bottom_reached=true;
        }

    }

    public void commandAction(Command c, Displayable d) {
        if (c == ok) {
            //switch back to getitemfromuser
            midlet.getDisplay().setCurrent(curdisp);
            //now open foodfile, this hasn't been done yet
            try {
                HelpDiabetes.foodfileinst = new FoodFile();
            } catch (Exception e) {

            }
        } else {//user pressed exit
            midlet.exitMIDlet();
        }
    }

    public synchronized void keyPressed(int keyCode) {
        if (getGameAction(keyCode)== UP) {
            if (offset < 0) {
                offset = offset + fonthght;
                bottom_reached=false;
            }
        } else if (getGameAction(keyCode) == DOWN) {
            if (!bottom_reached) {
                offset = offset - fonthght;
            }
        }
    }

    String GetClassName() {
        return("InitialScreen");
    }

}
